#include "copi_ui.h"

#include <float.h>
#include <imgui.h>
#include <imgui_colorbutton.h>

#if __cplusplus
extern "C" {
#endif
#include <lauxlib.h>
#include <lua.h>
#include <lualib.h>

static int copi_theme_light( lua_State* L )
{
    ImGui::StyleColorsLight();
    return 0;
}

static int copi_theme_classic( lua_State* L )
{
    ImGui::StyleColorsClassic();
    return 0;
}

static int copi_theme_dark( lua_State* L )
{
    ImGui::StyleColorsDark();
    return 0;
}

static int copi_ui_window_begin( lua_State* L )
{
    const char* str = lua_tostring( L, 1 );
    int         w   = lua_tonumber( L, 2 );
    int         h   = lua_tonumber( L, 3 );
    bool        a   = true;
    bool        rvl = ImGui::Begin( str,
                             &a,
                             ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar |
                                 ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize |
                                 ImGuiWindowFlags_NoScrollbar );
    ImGui::SetWindowSize( str, ImVec2( w, h ) );
    ImGui::SetWindowPos( str, ImVec2( 0, 0 ) );
    lua_pushboolean( L, rvl );
    return 1;
}

static int copi_ui_window_end( lua_State* L )
{
    ImGui::End();
    return 0;
}

static int copi_ui_text( lua_State* L )
{
    const char* str = lua_tostring( L, 1 );
    ImGui::Text( str );
    return 0;
}

static int copi_ui_separator_text( lua_State* L )
{
    const char* str = lua_tostring( L, 1 );
    ImGui::SeparatorText( str );
    return 0;
}

static int copi_ui_sameline( lua_State* L )
{
    const char* str = lua_tostring( L, 1 );
    ImGui::SameLine();
    return 0;
}

static int copi_ui_color_button( lua_State* L )
{
    const char* str = lua_tostring( L, 1 );
    bool        rvl = ImGui::ColoredButtonV1( str,
                                       ImVec2( -FLT_MIN, 0.0f ),
                                       IM_COL32( 255, 255, 255, 255 ),
                                       IM_COL32( 200, 60, 60, 255 ),
                                       IM_COL32( 180, 40, 90, 255 ) );
    lua_pushboolean( L, rvl );
    return 1;
}

static int copi_ui_button( lua_State* L )
{
    const char* str = lua_tostring( L, 1 );

    bool rvl = ImGui::Button( str );

    lua_pushboolean( L, rvl );
    return 1;
}

#if __cplusplus
}
#endif
